﻿using System.Web.Mvc;
using Wisdom.Core;

namespace Wisdom.Web.Mvc
{
    /// <summary>
    /// Defines a class to configure <seealso cref="FilterAttribute"/> for <see cref="Controller"/> or action methods.
    /// </summary>
    [DependsOn(typeof(RegisterFilters))]
    public abstract class ConfigureFiltersBase : BootstrapperTask
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ConfigureFiltersBase"/> class.
        /// </summary>
        /// <param name="registry">The registry.</param>
        protected ConfigureFiltersBase(IFilterRegistry registry)
        {
            Guard.IsNotNull(registry, "registry");

            Registry = registry;
        }

        /// <summary>
        /// Gets the filter registry.
        /// </summary>
        /// <value>The filter registry.</value>
        protected IFilterRegistry Registry
        {
            get;
            private set;
        }

        /// <summary>
        /// Executes the task.
        /// </summary>
        /// <returns></returns>
        public override TaskContinuation Execute()
        {
            Configure();

            return TaskContinuation.Continue;
        }

        /// <summary>
        /// Configures the filters.
        /// </summary>
        protected abstract void Configure();
    }
}